package com.onesports.intelligent.k12.polarlight.controller.operation.order;

import cn.gjing.excel.executor.ExcelFactory;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.operation.PageOrderDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.market.TotalDataVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.order.OrderByIdVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.order.OrderPageVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.order.OrganAndCampusVO;
import com.onesports.intelligent.k12.polarlight.service.order.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @author chenrl
 **/
@Api(tags = "运营端-运营管理-课程订单")
@RestController
@RequiredArgsConstructor
@RequestMapping(ApiPathConstants.ORDER)
public class OrderController {

    private final OrderService orderService;

    @ApiOperation("分页查询订单信息")
    @GetMapping("/select-page")
    public ResponseEntity<TotalDataVO<OrderPageVO>> selectPage(@Valid PageOrderDTO pageOrderDTO) {
        return ResultUtil.success(orderService.selectPageTotal(new Page<OrderPageVO>(pageOrderDTO.getPage(),pageOrderDTO.getRow()),pageOrderDTO));
    }

    @ApiOperation("订单导出")
    @GetMapping("/export")
    public void export(HttpServletResponse response, PageOrderDTO dto) {
        List<OrderPageVO> orderPageVOS = orderService.selectExprotTotal(dto);
        ExcelFactory.createWriter(OrderPageVO.class, response)
                .write(orderPageVOS).flush();
    }

    @ApiOperation("根据id查询订单信息")
    @GetMapping("/select-by-id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", required = true, dataType = "String", paramType = "query"),
    })
    public ResponseEntity<OrderByIdVO> selectById(String orderId) {
        return ResultUtil.success(orderService.selectById(orderId));
    }

    @ApiOperation("查询运营团队-校区信息")
    @GetMapping("/select-by-o")
    public ResponseEntity<OrganAndCampusVO> selectByo() {
        return ResultUtil.success(orderService.selectByOAndC());
    }
}













